<?php
include_once '../includes/common.php';
if($islogin2==1){}else sysmsg("您还未登录，请先登录",2,'./login.php',true);
if(isset($_GET['id'])) {
$id=isset($_GET['id'])?intval($_GET['id']):sysmsg("参数错误",2,'./',true);
$row=$DB->get_row("SELECT * FROM authguao_shop WHERE id='{$id}' limit 1");
if(!$row)sysmsg("授权平台不存在该商品",2,'./addshop.php',true);
if($row['uid']!=$userrow['uid'])sysmsg("无法管理他人上架的商品",2,'./addshop.php',true);
if($conf['Market_open']!=1)showmsg('错误', '授权平台未开放商城系统！', 4, './');
$title='编辑商品内容';
include_once './header.php';
if ($row['type'] == 1) {
    $type_name = '模板类商品';
} else if ($row['type'] == 2) {
    $type_name = '插件类商品';
} else if ($row['type'] == 3) {
    $type_name = '其他类商品';
} else {
    $type_name = '未知类商品';
}
?>
<style>
.image img {width: 120px;height: 120px;margin: 0.3em;box-shadow: 3px 3px 18px 1px #ccc}
</style>
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-header">
                编辑商品内容
            </div>
            <div class="card-body">
                <form class="form-horizontal layui-form">
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">商品编号：</label>
                        <input type="text" class="form-control" value="<?php echo $id;?>" disabled>
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">商品类型：</label>
                        <input type="text" class="form-control" value="<?php echo $type_name;?>" disabled>
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">商品名称：</label>
                        <input type="text" class="form-control" value="<?php echo $row['name'];?>" disabled>
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">下载链接：</label>
                        <input type="text" class="form-control" name="filedata" value="<?php echo $row['filedata'];?>" placeholder="请填写文件下载链接" lay-verType="tips" lay-verify="required">
                        <small>可编辑卖家购买后的商品下载链接<font color="red">可填写压缩包下载链接,或直接蓝奏云链接等外链下载地址！</font></small>
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">商品售价：</label>
                        <input type="text" class="form-control" name="money" value="<?php echo $row['money'];?>" placeholder="请填写这个商品的售价" lay-verType="tips" lay-verify="required">
                        <small>未认证商品上架后会默认显示您设置的价格！,每单商品您可以获得最少<font color="red"><?php echo $conf['shop_tcbl'];?>%</font>的商品提成,可用于提现!</small>
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">商品图片：</label>
                        <input type="text" class="form-control" name="image" value="<?php echo $row['image'];?>" lay-verType="tips" lay-verify="lay-verType="tips" lay-verify="required"">
                        <small>图片外链可使用晴天内部图床 <a href="http://cdn.vue8.cn/" style="color: cornflowerblue;">点击进入晴天云盘(可做图片外链)</a><br><font color="darkmagenta">多张图片可用英文逗号(,)分割!如[图片链接1,图片链接2,图片链接3]</font></small>
                    </div>
                    <div class="form-group mb-3" id="iamge_le" style="display: none;">
                        <div class="image"></div>
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">商品版本：</label>
                        <input type="text" class="form-control" name="version" value="<?php echo $row['version'];?>" placeholder="请填写商品版本号" lay-verType="tips" lay-verify="required">
                        <small>可编辑商品版本号,若和原来不一致，则提示更新！</small>
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">版本日志：</label>
                        <textarea class="form-control" name="updatelog" style="height:100px;" placeholder="请填写商品版本日志,可留空,用于后续更新！" lay-verType="tips" lay-verify="required"><?php echo $row['updatelog'];?></textarea>
                        <small>投稿商品默认为1.0版本,可填写相关更新日志等,和商品介绍不同,后续升级版本可在我的商品内点按钮升级更新内容</small>
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">商品介绍：</label>
                        <textarea class="form-control" name="recommend" style="height:100px;" placeholder="请填写文字介绍内容!推荐20字以内" lay-verType="tips" lay-verify="required"><?php echo $row['recommend'];?></textarea>
                    </div>
                    <button type="submit" class="btn btn-block btn-xs btn-outline-success" lay-submit lay-filter="submit_shopedit">修 改</button>
                </form>
            </div>
        </div>
    </div>
</div>
<?php
include_once './bottom.php';
?>
<script type="text/javascript">
layui.use(['form'], function () {
    var form = layui.form;
    form.on('submit(submit_shopedit)', function (data) {
        shopedit();
        return false;
    });
});
function image_fenltt(image) {
    var image_arr = image.split(",");
    var content = "";
    for (a in image_arr) {
        content += '<img layer-pid="' + a + '" alt="' + a + '" layer-src="' + image_arr[a] + '" src="' + image_arr[a] + '" />';
    }
    $(".image").html(content);
}
var images = $('input[name="image"]').val();
if (images != '') {
    $("#iamge_le").show(200);
    image_fenltt(images);
}
$('input[name="image"]').bind('input propertychange', function () {
    var image_log = $('input[name="image"]').val();
    if (image_log != '') {
        $("#iamge_le").show(200);
        image_fenltt(image_log);
    } else {
        $("#iamge_le").hide(200);
    }
});
function shopedit() {
    var filedata = $("input[name='filedata']").val();
    var money = $("input[name='money']").val();
    var image = $("input[name='image']").val();
    var version = $("input[name='version']").val();
    var updatelog = $("textarea[name='updatelog']").val();
    var recommend = $("textarea[name='recommend']").val();
    layer.open({
        title: '操作提示',
        content: '是否执行该操作！',
        icon: 3,
        btn: ['确定', '取消'],
        btn1: function (layero, index) {
            var ii = layer.msg('商品数据更新中', {icon: 16, time: 10 * 1000});
            $.ajax({
                type: "POST",
                url: "ajax.php?act=shopedit&id=<?php echo $id;?>",
                data : {filedata:filedata,money:money,image:image,version:version,updatelog:updatelog,recommend:recommend},
                dataType: "json",
                success: function(data) {
                    layer.close(ii);
                    if (data.code == 0) {
                        layer.msg(data.msg, {
                            icon: 6,
                            end: function (layero, index) {
                                window.location.reload();
                            }
                        });
                    } else {
                        layer.msg(data.msg, {icon: 5});
                    }
                },
                error:function(data){
                    layer.msg('服务器错误', {icon: 5});
                    return false;
                }
            });
        }
    });
    return false;
};
</script>
<?php
}else{
    sysmsg("参数错误",2,'./',true);
}
?>